/**
 * 将时间格式化为xx分钟前 xx小时前
 * @param date 时间
 * @returns updateDate 格式化的时间
 */
export const useResetDate = (date: string) => {
  const currentTime = new Date().getTime()
  const timeDifference = currentTime - new Date(date).getTime()

  const minutes = Math.floor(timeDifference / (1000 * 60))
  const hours = Math.floor(timeDifference / (1000 * 60 * 60))
  const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24))
  const years = Math.floor(timeDifference / (1000 * 60 * 60 * 24 * 365))

  let timeDiff = {
    unit: '秒',
    value: 0
  }

  //超过一年的，直接按年处理
  if (years > 0) {
    return {
      unit: '年',
      value: years
    }
  }

  if (days > 0) {
    return {
      unit: '天',
      value: days
    }
  }

  if (hours > 0) {
    return {
      unit: '小时',
      value: hours
    }
  }

  if (minutes > 0) {
    return {
      unit: '分钟',
      value: minutes
    }
  }

  return timeDiff
}
